package com.southwind.phone_store_demo.controller;

import com.southwind.phone_store_demo.service.PhoneService;
import com.southwind.phone_store_demo.util.ResultVOUtil;
import com.southwind.phone_store_demo.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/phone")
public class PhoneHandler {

    @Autowired
    private PhoneService phoneService;

    @GetMapping("/index")
    public ResultVO index(){
        return ResultVOUtil.success(phoneService.findDataVO());
    }


//    通过手机类别找手机
    @GetMapping("/findByCategoryType/{categoryType}/{currentPage}/{pageSize}")
    public ResultVO findByCategoryType(
            @PathVariable("categoryType") Integer categoryType,
            @PathVariable("currentPage") Integer currentPage,
            @PathVariable("pageSize") Integer pageSize){
        return ResultVOUtil.success(phoneService.findPhoneInfoVOByCategoryType(categoryType,currentPage,pageSize));

    }

//    @GetMapping("/findByCategoryType/{categoryType}")
//    public ResultVO findByCategoryType(
//           @RequestBody Integer categoryType){
//        return ResultVOUtil.success(phoneService.findPhoneInfoVOByCategoryType(categoryType));
//
//    }
    

//    通过手机
    @GetMapping("/findSpecsByPhoneId/{phoneId}")
    public ResultVO findSpecsByPhoneId(
            @PathVariable("phoneId") Integer phoneId){
        return ResultVOUtil.success(phoneService.findSpecsByPhoneId(phoneId));
    }
}
